package com.study.design.pattern.pattern.behavioral.Iterator;

import java.util.Iterator;

/**
 * @Author: gongsl
 * @Date: 2025-03-23 11:24
 */
public class BookExample {
    public static void main(String[] args) {
        BookShelf books = new BookShelf();
        books.addBook(new Book("Java核心技术", "Cay S. Horstmann"));
        books.addBook(new Book("设计模式", "Erich Gamma"));

        System.out.println("====== 增强for循环遍历 ======");
        for (Book book : books) {
            System.out.println(book);
        }

        System.out.println("\n====== iterator遍历 ======");
        Iterator<Book> it = books.iterator();
        while (it.hasNext()) {
            Book book = it.next();
            System.out.println(book);
        }

        System.out.println("\n====== forEach遍历 ======");
        books.forEach(System.out::println);
    }
}
